package com.wuyi.controller;

import com.github.pagehelper.PageInfo;
import com.wuyi.pojo.Post;
import com.wuyi.pojo.vo.PostRecommendVO;
import com.wuyi.service.IndexService;
import com.wuyi.service.PostService;
import com.zc.utils.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 曾川
 * @version 1.0.0
 * @ClassName IndexController.java
 * @Description 用于首页的相关接口
 * @createTime 2021年11月02日 23:12:00
 */
@Api(value = "首页",tags = {"用于首页的相关接口"})
@RestController
@RequestMapping("index")
public class IndexController {

    public static final String USER_TOKEN = "user_token";

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    private IndexService indexService;

    @Autowired
    private PostService postService;


    @ApiOperation(value = "按分类查询列表（已对接）", notes = "按分类查询列表（已对接）", httpMethod = "GET")
    @GetMapping("/catList")
    public JSONResult catList(@ApiParam(name = "categoryId", value = "分类Id", required = true)
                              @RequestParam Integer categoryId,
                              @ApiParam(name = "userName", value = "登录用户userName", required = false)
                              @RequestParam String userName,
                              @RequestParam( required = false,defaultValue = "1")Integer pageNum,
                              @RequestParam( required = false,defaultValue = "10")Integer pageSize) {
        if (null == categoryId) {
            return JSONResult.errorMsg("categoryId不能为空");
        }

        PageInfo pageInfo = indexService.catList(categoryId, userName, pageNum, pageSize);
        return JSONResult.ok(pageInfo);
    }

    @ApiOperation(value = "首页推荐帖子列表（已对接）", notes = "首页推荐帖子列表（已对接）", httpMethod = "GET")
    @GetMapping("/recommendList")
    public JSONResult recommendList(@RequestParam( required = false,defaultValue = "1")Integer pageNum,
                                    @RequestParam( required = false,defaultValue = "4")Integer pageSize) {
        PageInfo postRecommendVOS = postService.recommendList(pageNum, pageSize);
        return JSONResult.ok(postRecommendVOS);
    }

    @ApiOperation(value = "首页优质问题解答列表（已对接）", notes = "推荐帖子列表（已对接）", httpMethod = "GET")
    @GetMapping("/answerList")
    public JSONResult answerList(@RequestParam( required = false,defaultValue = "1")Integer pageNum,
                                 @RequestParam( required = false,defaultValue = "4")Integer pageSize) {
//        List<PostRecommendVO> postRecommendVOS = postService.recommendList(pageNum, pageSize);
        PageInfo pageInfo = postService.answerList(pageNum, pageSize);
        return JSONResult.ok(pageInfo);
    }



    /*@ApiOperation(value = "按分类查询列表调试收藏关注显示", notes = "按分类查询列表调试收藏关注显示", httpMethod = "GET")
    @GetMapping("/catListTest")
    public JSONResult catListTest(@RequestParam Integer categoryId,
                                  @RequestParam String userName,
                                  @RequestParam( required = false,defaultValue = "1")Integer pageNum,
                                  @RequestParam( required = false,defaultValue = "10")Integer pageSize) {

        if (null == categoryId) {
            return JSONResult.errorMsg("categoryId不能为空");
        }


        PageInfo pageInfo = indexService.catListTest(categoryId, userName, pageNum, pageSize);
        return JSONResult.ok(pageInfo);
    }*/




    @ApiOperation(value = "查询交流区列表（已对接）", notes = "查询交流区列表（已对接）", httpMethod = "GET")
    @GetMapping("/postList")
    public JSONResult postList(@RequestParam( required = false,defaultValue = "1")Integer pageNum,
                               @RequestParam( required = false,defaultValue = "10")Integer pageSize) {
        PageInfo pageInfo = postService.postList(pageNum, pageSize);
        return JSONResult.ok(pageInfo);
    }











}
